const path = require('path');
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");

module.exports = {
  entry: {
    vendor: ['vuex','mint-ui','iscroll/build/iscroll-probe'],
    app: "./src/app.js"
  },
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "[name].bundle.js",
    chunkFilename: '[name].chunk.js'
    // publicPath: "/assets/"
  },
  externals: {
    vue: "Vue"
  },
  module: {
    rules: [{
      test: /\.js$/,
      exclude: /node_modules/,
      loader: "babel-loader"
    }, {
      test: /\.vue$/,
      loader: "vue-loader"
    }, {
      test: /\.(png|jpg|gif)$/,
      use: [
        {
          loader: 'url-loader',
          options: {
            limit: 8192
          }
        }
      ]
    }, {
      test: /\.(woff|woff2|eot|ttf|otf|svg)$/,
      use: 'file-loader'
    }, {
      test: /\.(pcss|css)$/,
      use: ExtractTextPlugin.extract({
        fallback: 'style-loader',
        use: [{
          loader: 'css-loader'
        },{
          loader: 'postcss-loader'
        }]
      })

      // use: [
      //   {
      //     loader: 'style-loader',
      //   },
      //   {
      //     loader: 'css-loader',
      //     options: {
      //       importLoaders: 1,
      //     }
      //   },
      //   {
      //     loader: 'postcss-loader'
      //   }
      // ]
    }]
  },
  devtool: "source-map",
  devServer: {
    contentBase: path.join(__dirname, "dist"),
    compress: true,
    port: 9000
  },
  plugins: [
    new webpack.optimize.CommonsChunkPlugin({
      name: "vendor",

      filename: "commons.js",
      // (the filename of the commons chunk)

      // minChunks: 3,
      // (Modules must be shared between 3 entries)

      // chunks: ["pageA", "pageB"],
      // (Only use these entries)
    }),
    new ExtractTextPlugin({
      filename: "[name].css",
      allChunks: true
    }),
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify('dev'),
      // 'process.env.BASE_API': JSON.stringify('http://dev.aloestec.com:8080/mockjs/3/'),
      'process.env.BASE_API': JSON.stringify('http://192.168.1.190:8081/'),
      // 'process.env.BASE_API': JSON.stringify('http://192.168.1.187:8080/'),
    }),
    new HtmlWebpackPlugin({
      template: "./index.html",
      filename: "index.html"
    })
  ]
}